package com.smh.a02CollectionsDemo1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class CollectionsDemo1 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();


        //批量添加
        Collections.addAll(list,1,2,3,4,5,6,7,8);
        System.out.println(list);

        //打乱
        Collections.shuffle(list);
        System.out.println(list);

        //sort
        Collections.sort(list);
        System.out.println(list);

        //sort
        Collections.sort(list,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(list);

        Collections.sort(list);
        //只能查升序
        System.out.println(Collections.binarySearch(list, 2));

        //拷贝
        //拷贝集合中的元素个数要大于等于被拷贝的集合中的元素,不然会报错.
        ArrayList<Integer> newList = new ArrayList<>();
        Collections.addAll(newList,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
        Collections.copy(newList,list);
        System.out.println(newList);

        //fill
        Collections.fill(newList,1);
        System.out.println(newList);

        //max
        System.out.println(Collections.max(list));
        //min
        System.out.println(Collections.min(list));

        //swap交换两索引所在的数据的位置
        Collections.swap(list,0,7);
        System.out.println(list);

    }
}
